//@author A0096759E

package storage;

import java.lang.reflect.Type;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

public class SavedEventsListDeserializer implements JsonDeserializer<SavedEventsList>{
	  private static final String KEYWORD_EVENTS = "events";

	  @Override
	  public SavedEventsList deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context)
	      throws JsonParseException {
		   final JsonObject jsonObject = json.getAsJsonObject();

		    // Delegate the deserialization to the context
		    final ScheduleEvent[] scheduleEventsList = context.deserialize(jsonObject.get(KEYWORD_EVENTS), ScheduleEvent[].class);
	
		    final SavedEventsList savedEventsList = new SavedEventsList();
		    savedEventsList.setSavedEventsList(scheduleEventsList);
		    return savedEventsList;
	    }
}
